<?php
/*
 * 信息提取函数
 * @package    module
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 1bd11922a2a707dbb003c1be533361c83141a11c $
 */
/**
 * Class Information
 */
class AutoInformation{

	private static $_table;
	private static $_tableData;

	private static function _getTable() {
		if (!empty(self::$_table)) {
			return self::$_table;
		} else {
			self::$_table = Table::name(Table::NAME_INFORMATION);
			return self::$_table;
		}
	}

	private static function _getTableData() {
		if (!empty(self::$_tableData)) {
			return self::$_tableData;
		} else {
			self::$_tableData = Table::name(Table::NAME_INFORMATION_DATA);
			return self::$_tableData;
		}
	}

	/**
	 * 根据车系获取
	 * @param     $carid
	 * @param int $limit
	 * @return array
	 */
	public static function byCar($carid, $limit=10) {
		global $db;
		$sql = "select * from ".self::_getTable()." where arcid = $carid  order by addtime DESC limit $limit";
		$info = $db->getAll($sql);
		if (count($info) == 10) {
			return $info;
		} else {
			$left = $limit - count($info);
			$brandId = AutoRank::getArbidByArcid($carid);
			$sql = "select * from ".self::_getTable()." where arbid = $brandId  order by addtime DESC limit $left";
			$leftInfo = $db->getAll($sql);
			$infos = array_merge($info, $leftInfo);
			return __($infos)->uniq('title');
		}

	}
}